package com.huaxin.common.view;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;

import com.huaxin.common.tools.Log;

/**
 * Created by Administrator on 2016/9/30.
 */
public class OverScrollRecyclerView extends RecyclerView {

    int mContentMaxMoveHeight = 600;
    private int mPaddingTop;
    private int mPaddingBottom;
    private int overHeight = 100;

    public OverScrollRecyclerView(Context context) {
        super(context);
        init();
    }



    public OverScrollRecyclerView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public OverScrollRecyclerView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {
        setPadding(getPaddingLeft(),getPaddingTop(),getPaddingRight(),getPaddingBottom());
    }

    @Override
    public void setPadding(int left, int top, int right, int bottom) {
        mPaddingTop = top;
        mPaddingBottom = bottom;
        super.setPadding(left, top+overHeight, right, bottom+overHeight);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);
        scrollTo(getScrollX(), getScrollY());
        post(new Runnable()
        {
            public void run()
            {
                scrollTo(0,overHeight);
            }
        });
    }

    protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) {
        Log.d("Zoes", "overScrollBy" + deltaY + "," + scrollRangeY + "," + scrollY + "," + maxOverScrollY);


        return super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent);
    }

    @Override
    public void scrollBy(int x, int y) {
        Log.d("Zoes","scrollBy " + x+","+y);
        super.scrollBy(x, y);
    }

    @Override
    protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
        Log.d("Zoes","onOverScrolled");
        super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
    }
}
